<template>
	<view class="mine-container" :style="{ height: `${windowHeight}px` }">
		<!--顶部个人信息栏-->
		<view class="nav-bg">
			<image class="nav-bg-img" src="/static/images/icon-login-bg.png" mode="widthFix"></image>
		</view>
		<view class="header-section">
			<view class="flex justify-between" @click="handleToInfo">
				<view class="flex align-center">
					<view v-if="!avatar" class="cu-avatar round bg-white">
						<view class="iconfont icon-people text-gray icon"></view>
					</view>
					<image v-if="avatar" @click="handleToAvatar" :src="avatar" class="cu-avatar xl round"
						mode="widthFix"></image>
					<view v-if="!userInfo.nickname" @click="handleToLogin" class="login-tip">点击登录</view>
					<view v-if="userInfo.nickname" @click="handleToInfo" class="user-info">
						<view>{{ userInfo.nickname }}</view>
						<view class="info-phone flex align-center">
							<image src="/static/images/icon/icon-mobile.png" mode="widthFix" class="icon-mobile">
							</image>
							{{ userInfo.mobile }}
						</view>
					</view>
				</view>
				<view class="flex align-center">
					<view class="iconfont icon-right"></view>
				</view>
			</view>
		</view>

		<view class="content-section">
			<view class="list-cell list-cell-arrow" @click="handleToNotice()">
				<view class="flex">
					<image class="cell-img" src="/static/images/icon/icon-mine-notice.png" mode="widthFix"></image>
					<view>通知公告</view>
				</view>
			</view>
			<view class="list-cell list-cell-arrow" @click="handleToStatic()">
				<view class="flex">
					<image class="cell-img" src="/static/images/icon/icon-check.png" mode="widthFix"></image>
					<view>统计分析</view>
				</view>
			</view>
			<view class="list-cell list-cell-arrow" @click="handleGoPage()">
				<view class="flex">
					<image class="cell-img" src="/static/images/icon/icon-rank.png" mode="widthFix"></image>
					<view>任务排行榜</view>
				</view>
			</view>
			<view class="list-cell list-cell-arrow" @click="handleGoPage()">
				<view class="flex">
					<image class="cell-img" src="/static/images/icon/icon-advice.png" mode="widthFix"></image>
					<view>周报日报</view>
				</view>
			</view>
		</view>
		<wm-watermark :text="waterMarkerText"></wm-watermark>
		<view class="copyright">
			<view>Copyright &copy; 鸿海鑫科技版权所有</view>
		</view>
	</view>
</template>

<script>
	import storage from '@/utils/storage'
	import wmWatermark from '@/components/watermark/watermark.vue'
	export default {
		data() {
			return {
				// name: this.$store.state.user.name,
				version: getApp().globalData.config.appInfo.version,
				// waterMarkerText: '鸿海鑫科技版权所有',
				userInfo: null
			}
		},
		components: {
			wmWatermark
		},
		created() {
			// console.log(this.$store.state)
			const userInfo = uni.getStorageSync('userInfo')
			// console.log('userInfo', userInfo)
			// this.waterMarkerText = this.$store.state.user.name
			// + new Date()
		},
		computed: {
			avatar() {
				return this.$store.state.user.avatar
			},
			windowHeight() {
				return uni.getSystemInfoSync().windowHeight - 50
			}
		},
		methods: {
			handleToInfo() {
				this.$tab.navigateTo('/pages/mine/info/index')
			},
			handleToEditInfo() {
				this.$tab.navigateTo('/pages/mine/info/edit')
			},
			handleToSetting() {
				this.$tab.navigateTo('/pages/mine/setting/index')
			},
			handleToLogin() {
				this.$tab.reLaunch('/pages/login/phonelogin/index')
			},
			handleToAvatar() {
				this.$tab.navigateTo('/pages/mine/avatar/index')
			},
			handleToStatic() {
				this.$tab.navigateTo('/pages/statistics/index')
			},
			handleLogout() {
				this.$modal.confirm('确定注销并退出系统吗？').then(() => {
					this.$store.dispatch('LogOut').then(() => {
						this.$tab.reLaunch('/pages/index')
					})
				})
			},
			handleToNotice() {
				uni.switchTab({
					url: '/pages/notice/list/index'
				})
			},
			handleGoPage() {
				this.$modal.showToast('模块建设中~')
			},
			getUerInfo() {
				this.$store.dispatch('GetUserInfo').then((res) => {
					console.log('ssdf', res)
					this.userInfo = res
					name = res.nickname
				})
			}
		},
		onLoad() {
			this.getUerInfo()
		}
	}
</script>
<style lang="scss">
	page {
		background-color: #fff;
	}

	.mine-container {
		width: 100%;
		height: 100%;

		.nav-bg {
			width: 100vw;
			height: 430rpx;
			opacity: 1;
			background: linear-gradient(179deg, #3878f9 0%, #74aafc 99%);
			position: absolute;
			top: 0;
			z-index: -1;

			.nav-bg-img {
				width: 100vw;
				position: absolute;
				bottom: -1rpx;
				left: 0;
			}
		}

		.header-section {
			padding: 60rpx 60rpx 180rpx;
			color: white;

			.login-tip {
				font-size: 32rpx;
				margin-left: 10px;
			}

			.cu-avatar {
				border: 4rpx solid rgba(237, 243, 255, 0.3);
				width: 140rpx;
				height: 140rpx;

				.icon {
					font-size: 40px;
				}
			}

			.iconfont {
				font-size: 50rpx;
			}

			.icon-mobile {
				width: 30rpx;
				margin-right: 5rpx;
			}

			.user-info {
				margin-left: 30rpx;
				font-size: 32rpx;

				.info-phone {
					font-size: 28rpx;
					margin-top: 10rpx;
				}
			}
		}
		.copyright {
			position: fixed;
			bottom: 0;
			margin-bottom: 30rpx;
			text-align: center;
			line-height: 60rpx;
			color: #999;
		     width: 100%;
		}
		.content-section {
			position: relative;
			top: -50px;
			padding: 20rpx;
			font-size: 32rpx;

			.list-cell {
				background-color: transparent;
			}
			.cell-img {
				width: 50rpx;
				height: 50rpx;
				margin-right: 30rpx;
			}
		}
	}
</style>